package com.quickcode.example.threadpool;

import lombok.extern.slf4j.Slf4j;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.*;

/**
 * Created by 张波 on 2019/10/25.
 */
@Slf4j
public class ThreadPoolExample1 {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
//        ExecutorService executorService = Executors.newFixedThreadPool(3);
//        ExecutorService executorService2 = Executors.newCachedThreadPool();
//        ExecutorService executorService3 = Executors.newSingleThreadExecutor();
        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(2);
        ScheduledFuture<String> schedule = scheduledExecutorService.schedule(new Callable<String>() {
            @Override
            public String call() throws Exception {
                log.info("call time:{}", new SimpleDateFormat("HH:mm:ss").format(new Date()));
                return "success";
            }
        }, 3, TimeUnit.SECONDS);

        String out = schedule.get();
        log.info("out:{}",out);
        scheduledExecutorService.shutdown();
    }

}
